package com.seeyon.apps.seepkk.form.workflowevent;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.seeyon.apps.kk.form.workflowevent.KkBaseExtendPlug;
import com.seeyon.apps.seepkk.manager.SeepManager;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.ctp.common.constants.ApplicationCategoryEnum;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.workflow.event.WorkflowEventData;
import com.seeyon.ctp.workflow.event.WorkflowEventResult;

public class SeepKkProviderExtendPlug extends KkBaseExtendPlug {

    private static final Log log = LogFactory.getLog(SeepKkProviderExtendPlug.class);
    private SeepManager seepManager;

    public SeepManager getSeepManager() {
        return seepManager;
    }

    public void setSeepManager(SeepManager seepManager) {
        this.seepManager = seepManager;
    }

    @Override
    public String getId() {
        return "seepKkProviderExtendPlug";
    }

    @Override
    public String getLabel() {
        return "会议日程提供者校验";
    }

    public ApplicationCategoryEnum getAppName() {
        return ApplicationCategoryEnum.form;
    }

    // 发起前事件
    public WorkflowEventResult onBeforeStart(WorkflowEventData data) {
        log.info("#强生客开,SeepPro start");
        WorkflowEventResult result = new WorkflowEventResult();
        Map<String, Object> formdata = data.getBusinessData();
        FormBean formBean = (FormBean) data.getBusinessData().get("formBean");
        FormDataMasterBean formDataMasterBean = (FormDataMasterBean) data.getBusinessData().get("formDataBean");

        String resultMsg = "";
        try {
            resultMsg = this.seepManager.isCheckProvider(formBean, formDataMasterBean.getAllDataMap(), formDataMasterBean, formdata);
        } catch (BusinessException e) {
            resultMsg = "会议日程提供者校验异常！";
        }
        log.info("#强生客开,SeepPro end:" + resultMsg);
        result.setAlertMessage(resultMsg);
        return result;
    }
}
